#include "Reactor.hpp"
#include <iostream>
#include <memory>
#include "Connection.hpp"
#include "Reactor.hpp"
#include "Listener.hpp"
#include "PackageParse.hpp"
#include "HandlerEvents.hpp"

int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        std::cout << "Useage:\n\t" << argv[0] << " port" << std::endl;
        return 0;
    }

    uint16_t port = std::stoi(argv[1]);
    // std::unique_ptr<EpollServer> svr = std::make_unique<EpollServer>(port);
    // svr->Loop();

    //创建reactor
    std::unique_ptr<Reactor> reac = std::make_unique<Reactor>();

    PackageParse pp;
    HandlerEvents he(std::bind(&PackageParse::Parse, &pp, std::placeholders::_1));
    //创建listener  对象
    Listener l(port,he);
    reac->AddConnection(l.Sockfd(), EPOLLIN | EPOLLET, std::bind(&Listener::Accepter, &l, std::placeholders::_1), nullptr, nullptr);

    reac->Dispatcher();

    return 0;
}